package com.yly.doctorapp.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.yly.doctorapp.R;
import com.yly.doctorapp.bean.ImageBean;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class PrescriptionImageAdapter extends BaseAdapter {
    private Context mContext;
    private List<ImageBean> imageList;

    public PrescriptionImageAdapter(Context mContext, List<ImageBean> imageList) {
        this.mContext = mContext;
        this.imageList = imageList;
    }

    @Override
    public int getCount() {
        return imageList.size();
    }

    @Override
    public Object getItem(int position) {
        return imageList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view = null;
        if (convertView == null) {
            view = View.inflate(mContext, R.layout.layout_image, null);
        } else {
            view = convertView;
        }
        if (null != imageList && imageList.size() > 0){
            ViewHolder holder = new ViewHolder(view);
            Glide.with(mContext).load(imageList.get(position).getImageUrl()).into(holder.ivPrecription);
        }
        return view;
    }


    static class ViewHolder {
        @BindView(R.id.iv_precription)
        ImageView ivPrecription;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
